package cn.dapeng.test;

import cn.dapeng.test.listener.ApplicationStartedListener;
import cn.dapeng.test.service.StudentService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * @BelongProject Default (Template) Project
 * @BelongPackage org.example
 * @Description TODO
 * @ClassName ${NAME}
 * @Author xupenghong
 * @Date 2024/6/27 15:31
 * @Version 1.0.0
 */
@SpringBootApplication
public class ClientRunner {
    public static void main(String[] args) {

        // 第一种运行方式 SPI
//        ApplicationContext acx = new AnnotationConfigApplicationContext(MessageOperateServiceLoad.class);
//        MessageOperate messageOperate = acx.getBean(MessageOperate.class);
//        messageOperate.sendMessage("hello");

        // 第二种运行方式 基于spring-boot的方式
        SpringApplication application = new SpringApplication(ClientRunner.class);

        application.addListeners(new ApplicationStartedListener());

        ConfigurableApplicationContext acx = application.run(args);

        if(acx.containsBean("studentService")) {
            StudentService studentService = (StudentService) acx.getBean("studentService");
            studentService.sayHi();
        }

        System.out.println();

    }
}